<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>课程管理</title>
	<link rel="stylesheet" href="../css/common2.css">
</head>
<style>
		.search_name {
			height: 35px;
			max-width: 135px;
			padding: 0 5px;
			margin-right: 5px;
		}
</style>
<body>

	<div id="vue-root">
		<div v-if="able.add" class="add" style="margin-top: 30px;">
			<a href="educational_course_item.html" style="color: white">添加课程</a>
		</div>
		
		<div class="refresh" onclick="location.reload()">刷新</div>
		<input class="search_name" placeholder="请输入课程名称" v-model="search.name">
		<img src="../image/search.png" height="35" width="35" class="search_img" @click="getData0">
		<div class="table">
			<table class="table_top">
				<thead>
					<tr>
						<th class="one">
							<input type="checkbox" class="check-box" v-model="all">
						</th>
						<th class="one">序号</th>
						<th class="two">课程名称</th>
						<th class="one">课程规则</th>
						<th class="one">收费方式</th>
						<th class="one">收费标准</th>
						<th class="one">编辑/删除</th>
					</tr>
				</thead>
				<tbody id="list">
					<tr v-for="(course,index) in list" :key="course.id">
						<td class="one">
							<input type="checkbox" class="check-box" v-model="course.checked">
						</td>
						<td class="one"> <span v-text="index+1"></span></td>
						<td class="two" v-text="course.name"></td>
						<td class="one" v-text="course.type === 0 ? '一对一' : '一对多'"></td>
						<td class="one">
							<span>{{ getDisplayText(course.classHour, course.month, course.dailyRate,
								course.quarterlyHarvest, course.forwardHarvest, course.lessonPackage, course.experience)
								}}</span>
							<!-- {{
								v-text="course.type === 0 ? '一对一' : '一对多'"
							}} -->
						</td>
						<td class="one">
							<span
								v-html="getChargeStandardText(course.classHour, course.month, course.dailyRate, course.quarterlyHarvest, course.forwardHarvest, course.lessonPackage, course.experience)"></span>
						</td>
						<!-- <td class="one" v-text="course.type"></td>
                        <td class="four" v-text="course.illustration"></td>
                        <td class="two" v-text="course.attachment"></td> -->
						<td class="one">
							<div class="option">
								<div v-if="able.edit" class="edit-icon option-icon">
									<a :href="'educational_course_item.html?id='+course.id"
										style="position: absolute; left: 20%; top: 30%;">
										<img class="img" src="../image/edit.png" height="20" width="20"
											onmouseover="this.src='../image/edit_light.png'"
											onmouseout="this.src='../image/edit.png'" />
									</a>
								</div>
								<div v-if="able.del" class="delete-icon option-icon" @click="del([course.id])"
									style="position: absolute; right: 20%; top: 30%;">
									<img class="img" src="../image/delete.png" height="20" width="20"
										onmouseover="this.src='../image/delete_light.png'"
										onmouseout="this.src='../image/delete.png'" />
								</div>
							</div>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<br>
		<div class="delete" @click="batchDelete" v-if="able.del">批量删除</div>
		<ul class="pagination" v-if="pages>1">
			<li>
				<a v-if="pageNum!=1" @click="pageNum=1">«</a>
				<a class="pages-jump" v-if="pageNum!=1" @click="pageNum--">‹</a>
				<a v-text="pageNum"></a>
				<a class="pages-jump" v-if="pageNum!=pages" @click="pageNum++">›</a>
				<a v-if="pageNum!=pages" @click="pageNum=pages">»</a>
			</li>
		</ul>
		<div style="float: right;">
			总共{{total}}条记录
			<select class="ui-select init" style="height:32px" v-model="pageSize">
				<option :value="10">每页10条</option>
				<option :value="30">每页30条</option>
				<option :value="100">每页100条</option>
			</select>
		</div>
	</div>

	<script src="/scriptZIP/qs.min.js"></script>
	<script src="/scriptZIP/vue.min.js"></script>
	<script src="/scriptZIP/axios.min.js"></script>
	<script src="/js/common.js"></script>
	<script src="/js/list.js"></script>
	<script src="/js/auth_util.js"></script>

	<script>

		var app = new Vue(merge({
			data: {
				urls: {
					del: '/pc/course/del'
				}
			},
			created: function () {
				var schoolId = top_params().id;
				if (!schoolId) {
					alert('未知学校');
					throw '未知学校';
				}
				this.urls.list = '/pc/course/list/' + schoolId;
				this.getData();
				abled('course', this);
			},
			methods: {
				getDisplayText:
					function (classHour, month, dailyRate, quarterlyHarvest, forwardHarvest, lessonPackage, experience) {
						let types = [];
						if (classHour && classHour.length > 0) types.push('按课时');
						if (month && month.length > 0) types.push('按月');
						if (dailyRate && dailyRate.length > 0) types.push('按天');
						if (quarterlyHarvest && quarterlyHarvest.length > 0) types.push('按季');
						if (forwardHarvest && forwardHarvest.length > 0) types.push('按期');
						if (lessonPackage && lessonPackage.length > 0) types.push('按课包');
						if (experience && experience.length > 0) types.push('按体验');
						return types.length > 0 ? types.join(' & ') : '未知';
					},

				getChargeStandardText: function (classHour, month, dailyRate, quarterlyHarvest, forwardHarvest, lessonPackage, experience) {
					let texts = [];

					// 格式化价格的函数
					function formatPrice(price) {
						return Number.isInteger(price) ? price : parseFloat(price).toFixed(2);
					}

					if (classHour && classHour.length > 0)
						texts.push(`<span>${classHour[0].name}(${formatPrice(classHour[0].price)}元/课时)</span>`);
					if (month && month.length > 0)
						texts.push(`<span>${month[0].name}(${formatPrice(month[0].price)}元/月)</span>`);
					if (dailyRate && dailyRate.length > 0)
						texts.push(`<span>${dailyRate[0].name}(${formatPrice(dailyRate[0].price)}元/天)</span>`);
					if (quarterlyHarvest && quarterlyHarvest.length > 0)
						texts.push(`<span>${quarterlyHarvest[0].name}(${formatPrice(quarterlyHarvest[0].price)}元/季)</span>`);
					if (forwardHarvest && forwardHarvest.length > 0)
						texts.push(`<span>${forwardHarvest[0].name}(${formatPrice(forwardHarvest[0].price)}元/期)</span>`);
					if (lessonPackage && lessonPackage.length > 0)
						texts.push(`<span>${lessonPackage[0].name}(${formatPrice(lessonPackage[0].price)}元/课包)</span>`);
					if (experience && experience.length > 0)
						texts.push(`<span>${experience[0].name}(${formatPrice(experience[0].price)}元/体验)</span>`);

					return texts.length > 0 ? texts.join('<br>') : '未知';
				}


			}
		}));
	</script>

</body>

</html>